<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>员工管理(回收站)</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
    <link rel="stylesheet" href="./static/css/font.css">
    <link rel="stylesheet" href="./static/css/xadmin.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="./static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./static/js/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a href="">基础信息管理</a>
        <a>
          <cite>员工管理(回收站)</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md14 x-so" onsubmit="return false;">
            <div class="layui-inline">
                <lable class="layui-form-label">姓名：</lable>
                <input type="text" name="keywordName" placeholder="请输入姓名" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-inline">
              <lable class="layui-form-label">性别：</lable>
              <div class="layui-input-inline">
                <select name="keywordGender" lay-verify="required">
                    <option value="0">所有</option>
                    <option value="1">男</option>
                    <option value="2">女</option>
                </select>
              </div>
            </div>
            <div class="layui-inline">
                <lable class="layui-form-label">职位：</lable>
                <div class="layui-input-inline">
                    <select name="keywordDepartmentCode" lay-verify="required">
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <lable class="layui-form-label">身份证号：</lable>
                <input type="text" name="keywordIdCard" placeholder="请输入身份证号码" autocomplete="off" class="layui-input">
            </div>
            <button class="layui-btn" id="btn-seach"><i class="layui-icon">&#xe615;</i></button>
        </form>
    </div>
    <xblock>
        <button class="layui-btn layui-btn-danger" id="delete-all" data-type="getCheckRows"><i class="layui-icon"></i>批量删除</button>
        <button class="layui-btn" onclick="window.location='${pageContext.request.contextPath}/baseInfo?m=workerManagePage'"><i class="layui-icon">&#xe65c;</i>返回员工管理</button>
    </xblock>
    <table class="layui-table" lay-filter="action" id="data-table"></table>

</div>
<script>
    layui.use(['table','form'], function () {
        $ = layui.jquery;
        var form = layui.form
        // 数据表格
        var table = layui.table;

        //第一个实例
        var tableIns = table.render({
            elem: '#data-table'
            , height: 480
            , url: '${pageContext.request.contextPath}/baseInfo?m=workerManage&workerIsDeleted=1' //数据接口
            , page: true //开启分页
            , cols: [[ //表头
                {type: 'checkbox', fixed: 'left'}
                , {field: 'workerId', title: '编号', width: 80, sort: true, fixed: 'left'}
                , {field: 'workerName', title: '姓名', width: 165}
                , {
                    field: 'department', title: '职位', width: 125, templet: (function (d) {
                        return d.department.departmentName;
                    })
                }
                , {
                    field: 'workerGender', title: '性别', width: 90, templet: function (d) {
                        return d.workerGender === 1 ? '男' : '女';
                    }
                }
                , {field: 'workerPhone', title: '电话', width: 170}
                , {field: 'workerSalary', title: '工资', width: 110, sort: true}
                , {field: 'workerIdCard', title: '身份证号码', width: 210}
                , {field: 'workerCreateTime', title: '创建时间', width: 210, sort: true}
                , {field: 'workerUpdateTime', title: '删除时间', width: 210, sort: true}
                , {title: '恢复', width: 110, toolbar: "#restoreTool"}
                , {title: '彻底删除', width: 110, toolbar: "#deleteTool"}
            ]]
        });

        // 获取职位分类数据
        $.ajax({
            type:"post",
            url:"${pageContext.request.contextPath}/department?m=getAllDepartment",
            dataType:"json",
            success:function (data) {
                if (data.code === 200){
                    $("select[name=keywordDepartmentCode]").empty();
                    $("select[name=keywordDepartmentCode]").append("<option value='0'>所有职位</option>");
                    $(data.data).each(function () {
                        $("select[name=keywordDepartmentCode]").append("<option value='"+this.departmentCode+"'>"+this.departmentName+"</option>")
                    });
                    // 重新渲染
                    form.render('select');
                }
            }
        });

        //监听工具条
        table.on('tool(action)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

            if (layEvent == 'del') {
                layer.confirm('真的删除行么？', function (index) {
                    // 发送ajax 去删除数据
                    $.ajax({
                        type: "post",
                        url: "${pageContext.request.contextPath}/baseInfo?m=realDelete",
                        data: {ids: [data.workerId]},
                        dataType: "json",
                        success: function (data) {
                            if (data.code === 200) {
                                // 数据重载
                                tableIns.reload();
                            }
                            layer.close(index);
                        }
                    });

                });
            } else if (layEvent == 'restore') {
                layer.confirm('确定要恢复该员工吗？', function (index) {
                    // 发送ajax 去删除数据
                    $.ajax({
                        type: "post",
                        url: "${pageContext.request.contextPath}/baseInfo?m=restore",
                        data: {restoreId: data.workerId},
                        dataType: "json",
                        success: function (data) {
                            if (data.code === 200) {
                                // 数据重载
                                tableIns.reload();
                            }
                            layer.close(index);
                        }
                    });

                });
            }
        });


        var $ = layui.$, active = {
            getCheckRows: function () { //获取选中数据
                var checkStatus = table.checkStatus('data-table')
                    , data = checkStatus.data;
                // 检测个数
                if (data.length === 0) {
                    layer.msg("至少选中一个!");
                    return;
                }

                layer.confirm('确定批量删除吗?', function (index) {
                    // 获取id
                    var ids = [];
                    $(data).each(function () {
                        ids.push(this.workerId);
                    });

                    $.ajax({
                        type: "post",
                        url: "${pageContext.request.contextPath}/baseInfo?m=realDelete",
                        data: {ids: ids},
                        dataType: "json",
                        success: function (data) {
                            if (data.code === 200) {
                                // 数据重载
                                tableIns.reload();
                            }
                            layer.close(index);
                        }
                    });
                });
                //layer.alert(JSON.stringify(ids));
            }
        };

        $('#delete-all').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        // 搜索
        $("#btn-seach").click(function () {
            // 获取搜索的数据
            var keywordName = $("input[name=keywordName]").val();
            var keywordGender = $("select[name=keywordGender]").val();
            var keywordDepartmentCode = $("select[name=keywordDepartmentCode]").val();
            var keywordIdCard = $("input[name=keywordIdCard]").val();

            var param = {
                workerName : keywordName,
                workerGender : keywordGender,
                workerDepartmentCode : keywordDepartmentCode,
                workerIdCard : keywordIdCard
            }

            // 重新加载表格
            tableIns.reload({
                where: param
            })
        });
    });


    /*用户-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            //发异步删除数据
            $(obj).parents("tr").remove();
            layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }

    function delAll(argument) {
        var data = tableCheck.getData();
        layer.confirm('确认要删除吗？' + data, function (index) {
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
    }
</script>

<%--删除操作的列--%>
<script type=“text/html” id="deleteTool">
      <a class="layui-btn layui-btn-danger layui-btn-xs"  lay-event="del"><i class="layui-icon">&#xe640;</i>彻底删除</a>

</script>

<%--恢复操作的列--%>
<script type=“text/html” id="restoreTool">
      <a class="layui-btn layui-btn-xs" lay-event="restore"><i class="layui-icon">&#xe9aa;</i>恢复</a>

</script>
</body>

</html>